<template>
  <el-dialog title="催单" :visible.sync="visible" width="600px" @closed="close">
    <div class="detail-content">
      <el-form ref="form" :model="query">
        <el-form-item label="">
          <el-radio-group v-model="query.radio" @change="radioChange">
            <el-radio label="立刻处理" />
            <el-radio label="半小时内处理" />
            <el-radio label="一小时内处理" />
          </el-radio-group>
          <el-input
            v-model="query.remark"
            type="textarea"
            rows="3"
            maxlength="254"
            show-word-limit
          />
        </el-form-item>
      </el-form>
      <div>
        <div class="reminder-title">催单记录</div>
        <el-timeline :reverse="reverse">
          <el-timeline-item
            v-for="(activity, index) in recordList"
            :key="index"
            :color="activity.color"
            :timestamp="activity.happentDt"
          >
            <span :style="{ color: activity.color }">{{ activity.regUser }}</span>
            <span :style="{ color: activity.color }">催单一次</span>
            <span :style="{ color: activity.color }">催单理由：{{ activity.remark }}</span>
          </el-timeline-item>
        </el-timeline>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        取消
      </el-button>
      <el-button type="primary" @click="submit">
        确定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { parseTime } from '@/utils'
  import { crmOrderUrgeList, urgeComplain, urgeRepair } from '@/api'
  export default {
    name: 'reminderDialog',
    props: {
      type: {
        type: String,
        default: () => { return '' }
      },
      clientSelected: {
        type: Object,
        default: () => { return {} }
      }
    },
    data() {
      return {
        visible: false,
        query: {
          radio: '',
          remark: ''
        },
        recordList: [],
        reverse: false
      }
    },
    methods: {
      open(val) {
        return new Promise((resolve) => {
          this.resolve = resolve
          this.visible = true
          if (val) {
            this.currentRow = val
            this.recordList = []
            this.getUrgeList()
          }
        })
      },
      close() {
        this.visible = false
        this.query = {
          remark: '',
          radio: ''
        }
      },
      radioChange() {
        this.query.remark = this.query.radio
      },
      async getUrgeList() {
        const param = {
          billCode: this.type === 'repair' ? this.currentRow.repairCode : this.currentRow.complainId,
          billType: this.type === 'repair' ? 3 : 4
          // corpSN: this.clientSelected.corpSN
        }
        const res = await crmOrderUrgeList(param)
        this.recordList = JSON.parse(res.data.urgebillList)
        console.log(this.recordList)
        if (this.recordList.length > 0) {
          this.recordList.forEach((item) => {
            item.happentDt = parseTime(item.happentDt)
            this.recordList[0].color = '#ED912E'
          })
        }
      },
      async submit() {
        if (this.type === 'repair') {
          const params = {
            billCode: this.currentRow.repairCode,
            remark: this.query.remark
            // corpSN: this.clientSelected.corpSN
          }
          const res = await urgeRepair(params)
          if (res && res.data) {
            this.$message.success('操作成功')
            this.close()
          }
        } else {
          const params = {
            complainId: this.currentRow.complainId,
            remark: this.query.remark
            // corpSN: this.clientSelected.corpSN
          }
          const res = await urgeComplain(params)
          if (res && res.data) {
            this.$message.success('操作成功')
            this.close()
          }
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .detail-content {
    max-height: 350px;
  }
  .reminder-title {
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: 600;
    color: #ED912E;
  }
</style>
